package logic

import (
	"book/book_srv/pb"
	"context"

	"book/api/internal/svc"
	"book/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type BookListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewBookListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BookListLogic {
	return &BookListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *BookListLogic) BookList(req *types.BookListRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	list, err := l.svcCtx.BookSrv.BookList(l.ctx, &pb.BookListReq{})
	if err != nil {
		return &types.Response{
			Code: -1,
			Msg:  "查询信息错误",
			Data: nil,
		}, nil
	}
	return &types.Response{
		Code: 200,
		Msg:  "查询信息成功",
		Data: map[string]interface{}{
			"BookList": list,
		},
	}, nil
}
